home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / QuickDraw / SetWindBackColor / SetWindBackColor.c < prev    next >
Encoding:
Text File  |  1997-06-19  |  3.0 KB  |  125 lines  |  [TEXT/CWIE]

  1.     //
  2.     //    You may incorporate this sample code into your
  3.     //    applications without restriction. This sample code has
  4.     //    been provided "AS IS" and the responsibility for its
  5.     //    operation is 100% yours. You are not permitted to
  6.     //    redistribute the source as "Apple sample code" after
  7.     //    having made changes. If you're going to re-distribute
  8.     //    the source, we require that you make it clear in the
  9.     //    source that the code was descended from Apple sample
  10.     //    code, but that you've made changes.
  11.     //
  12.  
  13. #define OLDROUTINELOCATIONS        0
  14. #define OLDROUTINENAMES            0
  15. #define SystemSevenOrLater        1
  16.  
  17. #ifndef __FONTS__
  18. #    include <Fonts.h>
  19. #endif
  20.  
  21. #ifndef __DIALOGS__
  22. #    include <Dialogs.h>
  23. #endif
  24.  
  25. #ifndef __QDOFFSCREEN__
  26. #    include <QDOffscreen.h>
  27. #endif
  28.  
  29. static pascal OSErr InitMac (void)
  30. {
  31.     MaxApplZone ( );
  32.     InitGraf (&(qd.thePort));
  33.     InitFonts ( );
  34.     InitWindows ( );
  35.     InitMenus ( );
  36.     TEInit ( );
  37.     InitDialogs (nil);
  38.  
  39.     return noErr;
  40. }
  41.  
  42. static pascal Boolean SetColorTableEntry (CTabHandle cth, short value, const RGBColor *rgbP)
  43. {
  44.     ColorSpecPtr    ctTable        = (**cth).ctTable;
  45.     short            ctSize        = (**cth).ctSize;
  46.  
  47.     while (ctSize > -1)
  48.     {
  49.         if (ctTable->value == value)
  50.         {
  51.             ctTable->rgb = *rgbP;
  52.             CTabChanged (cth);
  53.             return true;
  54.         }
  55.  
  56.         ++ctTable;
  57.         --ctSize;
  58.     }
  59.  
  60.     return false;
  61. }
  62.  
  63. void main (void)
  64. {
  65.     if (InitMac ( ))
  66.         SysBeep (10);
  67.     else
  68.     {
  69.         WindowRef        window;
  70.         Rect            boundsRect        = qd.screenBits.bounds;
  71.  
  72.         //
  73.         //    [1] Create a window which covers most of the main screen.
  74.         //    Make it invisible for now.
  75.         //
  76.         //    [2] Get the window's color table.
  77.         //
  78.         //    [3] 'winCTabHandle' is the default color table because we've
  79.         //    just now created the window out of thin air. We don't want
  80.         //    to change the default color table, so make a copy.
  81.         //
  82.         //    [4] Set the background entry (0) of the color table.
  83.         //
  84.         //    [5] Set the window's color table.
  85.         //
  86.         //    [6] Up till now, none of the changes we've made have been
  87.         //    visible. That's the way we've wanted it because the whole
  88.         //    purpose here is to avoid visible changes, which result in
  89.         //    flicker.
  90.         //
  91.         //    [7] Wait for the user to click,
  92.         //    then put a smart-aleck message in the debugger.
  93.         //
  94.  
  95.         InsetRect (&boundsRect,10,10);                                                        // 1
  96.         boundsRect.top += GetMBarHeight ( );                                                // 1
  97.         window = NewCWindow (nil,&boundsRect,"\p",false,plainDBox,(WindowRef)-1,false,0);    // 1
  98.         if (window)                                                                            // 1
  99.         {
  100.             WCTabHandle        winCTabHandle;                                                    // 2
  101.             AuxWinHandle    auxWinHandle;                                                    // 2
  102.  
  103.             GetAuxWin (window,&auxWinHandle);                                                // 2
  104.             winCTabHandle = (WCTabHandle) ((**auxWinHandle).awCTable);                        // 2
  105.  
  106.             HandToHand ((Handle *) &winCTabHandle);                                            // 3
  107.             if (!MemError ( ))                                                                // 3
  108.             {
  109.                 RGBColor blackness = { 0, 0, 0 };                                            // 4
  110.  
  111.                 if (SetColorTableEntry ((CTabHandle) winCTabHandle, 0, &blackness))            // 4
  112.                 {
  113.                     SetWinColor (window,winCTabHandle);                                        // 5
  114.  
  115.                     ShowWindow (window);                                                    // 6
  116.  
  117.                     while (!Button ( )) ;                                                    // 7
  118.                     DebugStr ("\pNotice any flicker? I thought not.");                        // 7
  119.                 }
  120.             }
  121.             DisposeWindow (window);
  122.         }
  123.     }
  124. }
  125.